﻿<Window x:Class="UltimatePoker.StartNewGameWizard"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:src="clr-namespace:UltimatePoker"
    Title="{Binding ElementName=LayoutRoot,Path=SelectedItem.Header}"
     Height="275" Width="500" ResizeMode="CanMinimize"
        WindowStartupLocation="CenterOwner">
    <Grid>
        <Border x:Name="connectionView" Visibility="Hidden" Opacity="0.7" Panel.ZIndex="1" Canvas.Top="30" Width="200" Height="100" Background="LightCyan" CornerRadius="9">
            <Label FontSize="16" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" >Connecting...</Label>
        </Border>
        <DockPanel LastChildFill="True" >
            <DockPanel.Resources>
                <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
                <src:InvertedBooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter"/>
                <Style x:Key="tabWithNoItemPanel" TargetType="{x:Type TabControl}" BasedOn="{StaticResource {x:Type TabControl}}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type TabControl}">
                                <Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition x:Name="ColumnDefinition0"/>
                                        <ColumnDefinition Width="0" x:Name="ColumnDefinition1"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition x:Name="RowDefinition1" Height="*"/>
                                    </Grid.RowDefinitions>
                                    <Border x:Name="ContentPanel" Grid.Column="0" Grid.Row="0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="1" KeyboardNavigation.TabNavigation="Local">
                                        <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}" x:Name="PART_SelectedContentHost" ContentSource="SelectedContent"/>
                                    </Border>
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>

                </Style>
            </DockPanel.Resources>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Bottom">
                <Button x:Name="prev" Margin="5" Width="80" Click="prev_Click">Previous</Button>
                <Button x:Name="next" Margin="5" Width="80" Click="next_Click">Next</Button>
                <Button x:Name="finish" Margin="5" Width="80" Click="finish_Click">Finish</Button>
            </StackPanel>
            <TabControl x:Name="LayoutRoot" Style="{StaticResource tabWithNoItemPanel}" SelectedIndex="0">
                <TabItem x:Name="selectGameTypeTab" Header="Select Game Type">
                    <StackPanel Margin="20,20,0,0" TextBlock.FontSize="16">
                        <RadioButton IsChecked="True"
                                 x:Name="singlePlayer">Single Player</RadioButton>
                        <RadioButton x:Name="multiplayer">Multiplayer</RadioButton>

                        <StackPanel Margin="30,5,0,0"
                        Visibility="{Binding ElementName=multiplayer,Path=IsChecked,Converter={StaticResource BooleanToVisibilityConverter}}">
                            <RadioButton x:Name="join" IsChecked="True">Join an existing Game</RadioButton>
                            <RadioButton x:Name="create">Host the Game</RadioButton>
                            <RadioButton x:Name="spectate">Spectate A Game</RadioButton>
                        </StackPanel>

                    </StackPanel>
                </TabItem>
                <TabItem x:Name="createNewGameTab" Header="Create New Game">
                    <TabControl SelectedIndex="0" TabStripPlacement="Bottom"  IsEnabled="{Binding Path=CanCreate}">
                        <TabItem Header="Simple">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="30"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left">Select Game Type</Label>
                                <ComboBox Grid.Row="0" Grid.Column="0" Margin="0,3,5,3" HorizontalAlignment="Right" Width="100"
              ItemsSource="{Binding Path=GameModes}" SelectedItem="{Binding Path=SelectedGame}"/>
                                <Label Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left">Select Pre-Set</Label>
                                <ComboBox Grid.Row="0" Grid.Column="1" Margin="0,3,5,3" HorizontalAlignment="Right" Width="130"
                                      ItemsSource="{Binding Path=ServerConfigurations}" SelectedItem="{Binding Path=SelectedPreset}"
                                      DisplayMemberPath="DisplayName"/>
                                <Label Grid.Row="1" Grid.Column="0" 
                                   Visibility="{Binding ElementName=singlePlayer,Path=IsChecked,Converter={StaticResource BooleanToVisibilityConverter}}">Add Computer Players</Label>
                                <TextBox HorizontalAlignment="Right" Text="{Binding Path=BotCount}" Grid.Row="1" Grid.Column="0" MinWidth="90" MaxLength="1" Margin="3"
                                     Visibility="{Binding ElementName=singlePlayer,Path=IsChecked,Converter={StaticResource BooleanToVisibilityConverter}}"/>
                            </Grid>
                        </TabItem>
                        <TabItem Header="Advanced">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="30"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <ComboBox Grid.Row="0" Grid.Column="0" Margin="5" HorizontalAlignment="Left" Width="100"
              ItemsSource="{Binding Path=GameModes}" SelectedItem="{Binding Path=SelectedGame}"/>
                                <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Right">
                                    <Label>Port</Label>
                                    <TextBox Text="{Binding Path=Port}" MinWidth="60" Margin="3"/>
                                </StackPanel>

                                <Label Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Content="Starting Money"/>
                                <TextBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" MinWidth="90" MaxLength="9" Text="{Binding Path=StartingMoney}" Margin="3"/>
                                <StackPanel Grid.Row="1" Grid.Column="0">
                                    <CheckBox IsChecked="{Binding Path=TournamentMode}">
                                        Tournament Mode
                                    </CheckBox>
                                    <CheckBox x:Name="acceptPlayerCheckbox" IsChecked="{Binding Path=AcceptsNewPlayers}">Accept New Players</CheckBox>
                                </StackPanel>
                                <Label Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Content="Small Raise"/>
                                <TextBox Text="{Binding Path=SmallRaise}" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" MinWidth="90" MaxLength="4" Margin="3"/>
                                <Label HorizontalAlignment="Left" Grid.Row="2" Grid.Column="0" Content="Ante"/>
                                <TextBox HorizontalAlignment="Right" Grid.Row="2" Grid.Column="0" Text="{Binding Path=Ante}" MinWidth="90" MaxLength="4" Margin="3"/>
                                <Label Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Content="Raise Limit"/>
                                <TextBox HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1" Text="{Binding RaiseLimit}" MinWidth="90" MaxLength="4" Margin="3"/>
                                <Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left">Add Computer Players:</Label>
                                <TextBox HorizontalAlignment="Right" Text="{Binding Path=BotCount}" Grid.Row="3" Grid.Column="0" MinWidth="90" MaxLength="1" Margin="3"/>
                                <Label Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" Content="Raise Blind Each Hand:"/>
                                <TextBox HorizontalAlignment="Right" Text="{Binding Path=AutoRaiseOnHand}" Grid.Row="3" Grid.Column="1" MinWidth="90" MaxLength="4" Margin="3"/>
                                <Label Grid.Row="4" Grid.Column="1" HorizontalAlignment="Left" Content="Player Time Limit"/>
                                <TextBox HorizontalAlignment="Right" Text="{Binding Path=TimeLimit}" Grid.Row="4" Grid.Column="1" MinWidth="90" MaxLength="2" Margin="3"/>
                            </Grid>
                        </TabItem>
                    </TabControl>
                </TabItem>
                <TabItem x:Name="waitForUsersTab" Header="Wait for users to connect">
                    <StackPanel>
                        <Label Visibility="{Binding ElementName=acceptPlayerCheckbox,Path=IsChecked,Converter={StaticResource InvertedBooleanToVisibilityConverter}}">Users can't connect after the game had started</Label>
                        <Label>Click Finish to start the game</Label>
                        <ListBox  x:Name="connectedPlayers" Height="120"/>
                    </StackPanel>
                </TabItem>
                <TabItem x:Name="joinGameTab" Header="Join Existing Game">
                    <Grid>
                        <Grid.Resources>
                            <src:NotConverter x:Key="NotConverter"/>
                            <DataTemplate x:Key="checkRegistration">
                                <CheckBox IsEnabled="false" IsChecked="{Binding Path=ServerDetails.CanConnect}"/>
                            </DataTemplate>
                        </Grid.Resources>

                        <Grid.RowDefinitions>
                            <RowDefinition Height="40"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="270"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="0">
                            <Label>Server Address (IP or DNS):</Label>
                            <TextBox x:Name="textBox1"
        Text="{Binding Path=ServerAddress,UpdateSourceTrigger=PropertyChanged}" MinWidth="100" Margin="5"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0">
                            <Label>Server Port:</Label>
                            <TextBox x:Name="textBox2"
        Text="{Binding Path=ServerPort,UpdateSourceTrigger=PropertyChanged}" MinWidth="60" Margin="5"/>
                        </StackPanel>
                        <ListView
            ItemsSource="{Binding Path=DiscoveredServers}" SelectedItem="{Binding Path=SelectedServer}"
            Grid.ColumnSpan="2" Grid.Row="1">
                            <ListView.View>
                                <GridView>
                                    <GridViewColumn Header="Running Game" DisplayMemberBinding="{Binding Path=ServerDetails.Game}"/>
                                    <GridViewColumn Header="Server Address" DisplayMemberBinding="{Binding Path=Endpoint.Uri}"/>
                                    <GridViewColumn Header="Registration Open" CellTemplate="{StaticResource checkRegistration}"/>
                                    <GridViewColumn Header="Signed in Players" DisplayMemberBinding="{Binding Path=ServerDetails.ConnectedPlayers}"/>
                                    <GridViewColumn Header="Current Hand" DisplayMemberBinding="{Binding Path=ServerDetails.CurrentHand}"/>
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </Grid>
                </TabItem>
            </TabControl>
        </DockPanel>
    </Grid>
</Window>
